package com.aeye.chatserver.Controller;


import com.aeye.chatserver.HttpModelUtil;
import com.aeye.chatserver.dto.ModelDTO;
import com.aeye.chatserver.dto.ResultDTO;
import com.alibaba.fastjson.JSONObject;
import com.google.cloud.speech.v1.*;
import com.google.protobuf.ByteString;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;

@RestController
@RequestMapping(value = "/tts")
@ResponseBody
public class TTSController {

    // 引用形式的描述信息
    @PostMapping("/upload")
    public ResultDTO handleFileUpload(@RequestParam("file") MultipartFile file) {
        // 处理文件上传逻辑
        // 引用形式的描述信息
        try{
            SpeechClient speechClient = SpeechClient.create();
            RecognitionConfig config = RecognitionConfig.newBuilder()
                    .setEncoding(RecognitionConfig.AudioEncoding.LINEAR16)
                    .setLanguageCode("en-US")
                    .build();
            RecognitionAudio audio = RecognitionAudio.newBuilder()
                    .setContent(ByteString.copyFrom(file.getBytes()))
                    .build();
            RecognizeResponse response = speechClient.recognize(config, audio);
            List<SpeechRecognitionResult> results = response.getResultsList();
            return null;
        }catch (Exception e){
            return ResultDTO.error(e.getMessage(), null);
        }
    }
}
